package day05;

import java.lang.reflect.Array;
import java.util.Arrays;

//冒泡排序
public class Bubblesort {
    public static void main(String[] args) {
        /*
        int[] arr = {34, 23, 31, 2};
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int t = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = t;
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+"\t");
        }
        System.out.println();

        for (int a:arr) {
            System.out.print(a+"\t");
        }
        System.out.println();

        System.out.println( Arrays.toString(arr));

         */
        int[] arr = {5, 4, 3, 2};
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int a = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = a;
                }
            }
        }
        for (int b : arr) {
            System.out.print(b + "\t");
        }

    }
}
